package messages;

import util.Utils;

public class ConnectRsp extends MessageHeader {

	public static final short	CONNECT_RSP_ID	= 2;

	private short				windowSize;
	private short				compatibility;
	private short				error;

	/* ---------------------------------------------------------------- CONSTRUCTORS */

	/**
	 * @param _destID
	 * @param _srcID
	 * @param _windowSize
	 * @param _compatibility
	 * @param _error
	 */
	public ConnectRsp( short _destID , short _srcID , short _windowSize , short _compatibility ,
			short _error ) {
		super( _destID , _srcID );
		concatCommandID( CONNECT_RSP_ID );
		concatWindowSize( _windowSize );
		concatCompatibility( _compatibility );
		concatError( _error );
	}

	/* ---------------------------------------------------------------- PRIVATE */

	/**
	 * @param commandID
	 */
	private void concatCommandID( short commandID ) {
		this.incrementLength( (short) 2 );
	}

	/**
	 * @param _windowSize
	 */
	private void concatWindowSize( short _windowSize ) {
		this.windowSize = _windowSize;
		this.incrementLength( (short) 2 );
	}

	/**
	 * @param _compatibility
	 */
	private void concatCompatibility( short _compatibility ) {
		this.compatibility = _compatibility;
		this.incrementLength( (short) 2 );
	}

	/**
	 * @param _error
	 */
	private void concatError( short _error ) {
		this.error = _error;
		this.incrementLength( (short) 2 );
	}

	/* ---------------------------------------------------------------- PUBLIC */

	public short getCompatibility( ) {
		return compatibility;
	}

	public void setCompatibility( short compatibility ) {
		this.compatibility = compatibility;
	}

	public short getWindowSize( ) {
		return windowSize;
	}

	public void setWindowSize( short windowSize ) {
		this.windowSize = windowSize;
	}

	public short getError( ) {
		return error;
	}

	public void setError( short error ) {
		this.error = error;
	}

	@Override
	public String toString( ) {
		byte[] _compatibility = Utils.shortToBytes( this.compatibility );
		byte[] _error = Utils.shortToBytes( this.error );
		return " [ CONNECT_RSP ] = " + super.toString( ) + " | <Command_ID=" + CONNECT_RSP_ID
				+ "> " + "| <WindowSize=" + this.windowSize + "> " + "| <CompatHigh="
				+ _compatibility[0] + ".CompatLow=" + _compatibility[1] + "> " + "| <Error="
				+ _error[0] + ".Return=" + _error[1] + "> | ";
	}
}
